import request from '@/utils/request'
import axios from 'axios'
import gconfig from '@/config/global_config'
//import { getToken } from '@/utils/storage'
/**
 * 用户登录
 * @param {string} userName 用户名
 * @param {string} password 密码
 * @returns promise
 */
function getTreeView(book_id) {
    return request({
        url: "/chapter/get_tree_view?book_id="+book_id,
        method: "get",
        data: {},
        needAuthentication: true
    })
}



function getFileContent(url) {
    return axios({
        url: gconfig.constants.API_ORIGIN + "/chapter/get_file_content?path=" + encodeURIComponent(url), // 使用encodeURIComponent确保URL参数被正确编码
        method: "get",
        responseType: 'blob',  // 设置响应类型为 'blob'，以便处理二进制数据流
        // headers: {
        //     'token' :getToken()
        // }
    });
    // return ({
    //     url: gconfig.constants.API_ORIGIN + "/chapter/get_test?path=" + url,
    //     method: "get",
    //     responseType: 'blob',
    //     data: {}
    // })
}

export { getTreeView, getFileContent }
